package com.example.sls.service.impl.Class;

import com.example.sls.mapper.Class.ClassMapper;
import com.example.sls.pojo.Class._Class;
import com.example.sls.service.Class.ClassService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ClassServiceImpl implements ClassService {
    @Autowired
    private ClassMapper classMapper;

    @Override
    public List<_Class> getClassesByTId(Integer teacherId) {
        return classMapper.getClassesByTId(teacherId);
    }

    @Override
    public List<_Class> getClassesInfo() {
        return classMapper.getClassesInfo();
    }

    @Override
    public _Class getClassInfoByCId(Integer CId) {
        return classMapper.getClassInfoByCId(CId);
    }

    @Override
    public Integer getCountByCId(Integer CId) {
        return classMapper.getCountByCId(CId);
    }

    @Override
    public Boolean setCountByCId(Integer CId, Integer cnt) {
        boolean flag = false;
        if(classMapper.setCountByCId(CId, cnt) > 0){
            flag = true;
        }
        return flag;
    }

    @Override
    public PageInfo<_Class> getPageInfoByTId(Integer tId, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum, pageSize);
        List<_Class> classes = classMapper.getClassesByTId(tId);
        return new PageInfo<_Class>(classes);
    }

    @Override
    public Boolean addClass(Map<String, Object> map) {
        boolean flag = false;
        if(classMapper.addClass(map) > 0 ){
            flag = true;
        }
        return flag;
    }

    @Override
    public Integer getMaxId() {
        return classMapper.getMaxId();
    }

    @Override
    public Integer getClassCount() {
        return classMapper.getClassCount();
    }
}
